package com.dhwl.hsh.merchant.ui.activity;

import android.os.Bundle;
import android.webkit.URLUtil;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dhwl.hsh.lib.bean.resp.MerchantResp;
import com.dhwl.hsh.lib.bean.resp.UserAuthResp;
import com.dhwl.hsh.lib.core.HshException;
import com.dhwl.hsh.lib.view.CircleImageView;
import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.merchant.presenter.UserAuthPresenter;
import com.dhwl.hsh.merchant.presenter.iview.IUserAuthView;

import butterknife.Bind;

/**
 * 个人信息详情
 *
 * @author Derek.Kidd
 * @time 2016/5/3 18:21
 */
public class PersonalInfoActivity extends BaseActivity implements IUserAuthView {


    @Bind(R.id.iv_user_head)
    CircleImageView ivUserHead;
    @Bind(R.id.tv_user_name)
    TextView tvUserName;
    @Bind(R.id.tv_phone)
    TextView tvPhone;

    @Bind(R.id.tv_merchant_add)
    TextView tvMerchantAdd;
    @Bind(R.id.tv_identify)
    TextView tvIdentify;
    @Bind(R.id.tv_merchant_identify)
    TextView tvMerchantIdentify;

    @Bind(R.id.img_identify_1)
    ImageView imgIdentify1;
    @Bind(R.id.img_identify_2)
    ImageView imgIdentify2;

    @Bind(R.id.img_merchant_1)
    ImageView imgMerchant1;
    @Bind(R.id.img_merchant_2)
    ImageView imgMerchant2;

    UserAuthPresenter userAuthPresenter;

    MerchantResp merchantInfo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_personal_info;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setTitleContent("信息认证");
    }

    @Override
    protected void initData() {

        userAuthPresenter = new UserAuthPresenter();
        userAuthPresenter.attachView(this);
        userAuthPresenter.getUserAuth();

        merchantInfo =   getIntent().getParcelableExtra("merchant_info");
        if(URLUtil.isNetworkUrl(merchantInfo.getPortraitPicUrl())){
            Glide.with(this).load(merchantInfo.getPortraitPicUrl()).into(ivUserHead);
        }

        tvUserName.setText(merchantInfo.getStoreName());
        //身份是否已认证
        if (merchantInfo.getCardAuthenState() == 1) {
            tvIdentify.setText(R.string.identity_authed);
            tvIdentify.setTextColor(getResources().getColor(R.color.color_ff9b1a_on));
        } else {
            tvIdentify.setText(R.string.identity_un_auth);
            tvIdentify.setTextColor(getResources().getColor(R.color.color_ff9b1a));
        }
        //商户是否已认证
        if (merchantInfo.getMerchantAuthenState() == 1) {
            tvMerchantIdentify.setText(R.string.identity_authed);
            tvMerchantIdentify.setTextColor(getResources().getColor(R.color.color_ff9b1a_on));
        } else {
            tvMerchantIdentify.setText(R.string.identity_un_auth);
            tvMerchantIdentify.setTextColor(getResources().getColor(R.color.color_ff9b1a));
        }
    }

    @Override
    public void onUserAuthSuccess(UserAuthResp userAuthResp) {

        tvPhone.setText(userAuthResp.getMobile());
        tvMerchantAdd.setText(userAuthResp.getStoreAddress());

        if(URLUtil.isNetworkUrl(userAuthResp.getCardPic1())){
            Glide.with(this).load(userAuthResp.getCardPic1()).into(imgIdentify1);
        }
        if(URLUtil.isNetworkUrl(userAuthResp.getCardPic2())){
            Glide.with(this).load(userAuthResp.getCardPic2()).into(imgIdentify2);
        }
        if(URLUtil.isNetworkUrl(userAuthResp.getStorePic1())){
            Glide.with(this).load(userAuthResp.getStorePic1()).into(imgMerchant1);
        }
        if(URLUtil.isNetworkUrl(userAuthResp.getStorePic2())){
            Glide.with(this).load(userAuthResp.getStorePic2()).into(imgMerchant2);
        }

    }

    @Override
    public void onUserAuthFailure(HshException e) {

    }
}
